package com.example;

import com.example.config.AppConfig;
import com.example.service.TaskService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MainApp {
    public static void main(String[] args) {
        System.out.println("=== Spring注解配置IOC容器 - 线程池示例 ===");

        // 1. 创建基于注解的Spring容器
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(AppConfig.class);

        System.out.println("✅ Spring IOC容器启动成功！");
        System.out.println("=====================================");

        // 2. 获取TaskService Bean
        TaskService taskService = context.getBean(TaskService.class);

        // 3. 执行任务
        System.out.println("🎬 开始执行并发任务...");
        taskService.executeTasks();

        System.out.println("=====================================");
        System.out.println("🎬 开始执行单个任务...");
        taskService.executeSingleTask();

        System.out.println("=====================================");
        System.out.println("🎉 程序执行完成！");

        // 4. 关闭容器
        context.close();
    }
}